home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / aros / source / exec / memory / src / allocentry.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-16  |  2.8 KB  |  116 lines

  1. /*
  2.     (C) 1995 AROS - The Amiga Replacement OS
  3.     $Id: allocentry.c 1.1 1995/11/14 22:31:07 digulla Exp digulla $
  4.     $Log: allocentry.c $
  5.  * Revision 1.1  1995/11/14  22:31:07  digulla
  6.  * Initial revision
  7.  *
  8.     Desc:
  9.     Lang: english
  10. */
  11. #include "exec_intern.h"
  12.  
  13. /*****************************************************************************
  14.  
  15.     NAME */
  16.     #include <exec/memory.h>
  17.     #include <clib/exec_protos.h>
  18.  
  19.     __AROS_LH1(struct MemList *, AllocEntry,
  20.  
  21. /*  SYNOPSIS */
  22.     __AROS_LA(struct MemList *, entry, A0),
  23.  
  24. /*  LOCATION */
  25.     struct ExecBase *, SysBase, 37, Exec)
  26.  
  27. /*  FUNCTION
  28.     Allocate a number of memory blocks through a MemList structure.
  29.  
  30.     INPUTS
  31.     entry - The MemList with one MemEntry for each block you want to get
  32.  
  33.     RESULT
  34.     The allocation was successful if the most significant bit of the
  35.     result is 0. The result then contains a pointer to a copy of
  36.     the MemList structure with the me_Addr fields filled.
  37.     If the most significant bit is set the result contains the type of
  38.     memory that couldn't be allocated.
  39.  
  40.     NOTES
  41.  
  42.     EXAMPLE
  43.  
  44.     BUGS
  45.  
  46.     SEE ALSO
  47.     FreeEntry()
  48.  
  49.     INTERNALS
  50.  
  51.     HISTORY
  52.     18-10-95    created by m. fleischer
  53.     26-10-95    digulla adjusted to new calling scheme
  54.  
  55. ******************************************************************************/
  56. {
  57.     __AROS_FUNC_INIT
  58.     struct MemList *ret;
  59.     ULONG mlsize,i;
  60.  
  61.     /* Calculate size of a MemList with ml_NumEntries MemEntries. */
  62.     mlsize=sizeof(struct MemList)-sizeof(struct MemEntry)+
  63.        sizeof(struct MemEntry)*entry->ml_NumEntries;
  64.  
  65.     /* Get the MemList structure */
  66.     ret=(struct MemList *)AllocMem(mlsize,MEMF_PUBLIC);
  67.  
  68.     /* Check nasty case where the returncode is misleading :-( */
  69.     if((ULONG)ret&0x80ul<<(sizeof(APTR)-1)*8)
  70.     {
  71.     FreeMem(ret,mlsize);
  72.     ret=NULL;
  73.     }
  74.  
  75.     /* The allocation failed? Return "no public memory" */
  76.     if(ret==NULL)
  77.     return (struct MemList *)(MEMF_PUBLIC|0x80ul<<(sizeof(APTR)-1)*8);
  78.  
  79.     /* Init new struct */
  80.     ret->ml_NumEntries=entry->ml_NumEntries;
  81.     ret->ml_Node.ln_Type=0;
  82.     ret->ml_Node.ln_Pri =0;
  83.     ret->ml_Node.ln_Name=NULL;
  84.  
  85.     /* Fill all entries */
  86.     for(i=0;i<entry->ml_NumEntries;i++)
  87.     {
  88.     /* Get one */
  89.     ret->ml_ME[i].me_Addr=AllocMem(entry->ml_ME[i].me_Length,
  90.                        entry->ml_ME[i].me_Reqs);
  91.     /* Got it? */
  92.     if(ret->ml_ME[i].me_Addr==NULL)
  93.     {
  94.         /* No. Set returncode to "none of the 'ml_ME[i].me_Reqs' memory". */
  95.         entry=(struct MemList *)
  96.           ((ULONG)entry->ml_ME[i].me_Reqs|0x80ul<<(sizeof(APTR)-1)*8);
  97.  
  98.         /* Free everything allocated until now... */
  99.         for(;i-->0;)
  100.         FreeMem(ret->ml_ME[i].me_Addr,ret->ml_ME[i].me_Length);
  101.  
  102.         /* ...including the MemList */
  103.         FreeMem(ret,mlsize);
  104.  
  105.         /* All done */
  106.         return entry;
  107.     }
  108.     /* Copy the Length field */
  109.     ret->ml_ME[i].me_Length=entry->ml_ME[i].me_Length;
  110.     }
  111.     /* Everything filled. Return OK. */
  112.     return ret;
  113.     __AROS_FUNC_EXIT
  114. } /* AllocEntry */
  115.  
  116.